﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace UI
{
    public partial class CarInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater1.DataSource = new CarInfoBLL().Dat();
                Repeater1.DataBind();
                DropDownList1.DataSource = new CarTypeBLL().Dat();
                DropDownList1.DataTextField = "TypeName";
                DropDownList1.DataValueField = "TypeID";
                DropDownList1.DataBind();
            }

        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Repeater1.DataSource = new CarInfoBLL().Dat();
            Repeater1.DataBind();

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
                int name = Convert.ToInt32(this.DropDownList1.SelectedValue);
                Repeater1.DataSource = new CarInfoBLL().Dat(name);
                Repeater1.DataBind();
            
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delect")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                new CarInfoBLL().Shan(id);
                Repeater1.DataSource = new CarInfoBLL().Dat();
                Repeater1.DataBind();
            }
            else if (e.CommandName == "update")
            {
                HttpCookie cookie = new HttpCookie("Name",e.CommandArgument.ToString());
                Response.Cookies.Add(cookie);
                Response.Redirect("UpdateCar.aspx");
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("InsertCar.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = this.TextBox1.Text;
            Repeater1.DataSource = new CarInfoBLL().TianJian(name);
            Repeater1.DataBind();

        }
    }
}